const http = require('http');
const querystring = require('querystring');

const server = http.createServer((req, res) => { 

    let str = '';
    let i = 0;

    // data 有数据到达的时候就会发生
    req.on('data', (data) => {
        console.log(`第${i++}次收到数据`)

        str += data;
    });

    // end事件只会发生一次
    req.on('end', () => {
        // console.log(str);
        let POST = querystring.parse(str);
        console.log(POST);
    });


    res.end();

}).listen(8000, () => {
    console.log('服务启动成功');
});